import { inject, nextTick, provide, ref } from "vue"

const routerAlive = Symbol()

export function provideReload() {
  const isRouterAlive = ref(true)

  function reload() {
    isRouterAlive.value = false
    nextTick(() => {
      isRouterAlive.value = true
    })
  }

  provide(routerAlive, reload)

  return {
    isRouterAlive
  }
}

export function useReload() {
  return inject(routerAlive)
}
